var a = getApp();

Page({
    data: {
        vertical: !1,
        autoplay: !0,
        interval: 2e3,
        duration: 500,
        category_index: "",
        page: 1
    },
    onLoad: function(a) {
        this.getdata();
    },
    changeCategory: function(a) {
        var t = a.currentTarget.dataset.id;
        console.log(t), this.setData({
            category_index: t
        }), this.getList(t);
    },
    gotoCaseDetail: function(a) {
        var t = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageE/others/case_library/case_detail/caseLibraryDetail?id=" + t
        });
    },
    gotoSpecial: function(a) {
        var t = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageE/others/case_library/subject_detail/caseLibrarySubjectDetail?id=" + t
        });
    },
    gotoOther: function(a) {
        console.log(a);
        var t = a.currentTarget.dataset.name;
        "new" == t ? wx.navigateTo({
            url: "/packageE/others/case_library/new_mobile/caseLibraryNewMobile?name=caseLibraryNewMobile"
        }) : "category" == t ? wx.navigateTo({
            url: "/packageE/others/case_library/category/caseLibraryCategory"
        }) : "ranking" == t ? wx.navigateTo({
            url: "/packageE/others/case_library/ranking_mobile/caseLibraryRankingMobile"
        }) : "area" == t ? wx.navigateTo({
            url: "/packageE/others/case_library/new_mobile/caseLibraryNewMobile?name=caseLibraryAreaMobile"
        }) : "subjectList" == t && wx.navigateTo({
            url: "/packageE/others/case_library/subject_list/caseLibrarySubjectList"
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var a = this.data.page + 1;
            this.setData({
                page: a
            }), this.getMoreData();
        }
    },
    onShareAppMessage: function() {},
    getdata: function() {
        var t = this, e = a.getNetAddresss("plugin.case-library.api.mobile.home.index");
        a._postNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (e.data.newCase && e.data.newCase.map(function(a) {
                    a.created_at = a.created_at.split(" ")[0];
                }), t.setData({
                    view_show: !0,
                    banner: e.data.banner,
                    newCase: e.data.newCase,
                    special: e.data.special,
                    hotCategory: e.data.hotCategory,
                    advert: e.data.advert,
                    ad1: e.data.advert.ad1.length && 0 == e.data.advert.ad1.length ? "" : e.data.advert.ad1,
                    ad2: e.data.advert.ad2.length && 0 == e.data.advert.ad2.length ? "" : e.data.advert.ad2,
                    hotCasesList: e.data.hotCases.data,
                    current_page: e.data.hotCases.current_page,
                    last_page: e.data.hotCases.last_page
                }), t.data.hotCategory.length >= 1 && t.setData({
                    category_index: t.data.hotCategory[0].id
                })) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getList: function(t) {
        wx.showLoading({
            title: "加载中"
        });
        var e = this, s = a.getNetAddresss("plugin.case-library.api.mobile.home.home-cut-category");
        this.setData({
            page: 1
        }), a._postNetWork({
            url: s,
            data: {
                cid: t
            },
            success: function(a) {
                wx.hideLoading({
                    success: function(a) {}
                });
                var s = a.data;
                1 == s.result ? (e.data.hotCasesList = [], e.setData({
                    touchId: t,
                    hotCasesList: s.data.hotCases.data,
                    current_page: s.data.hotCases.current_page,
                    last_page: s.data.hotCases.last_page
                })) : wx.showToast({
                    title: s.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a), wx.hideLoading({
                    success: function(a) {}
                });
            }
        });
    },
    getMoreData: function() {
        wx.showLoading({
            title: "加载中"
        });
        var t = this, e = a.getNetAddresss("plugin.case-library.api.mobile.home.home-cut-category");
        a._postNetWork({
            url: e,
            data: {
                cid: t.data.touchId || t.data.hotCategory[0].id,
                page: t.data.page
            },
            success: function(a) {
                wx.hideLoading({
                    success: function(a) {}
                });
                var e = a.data;
                1 == e.result ? t.setData({
                    hotCasesList: t.data.hotCasesList.concat(e.data.hotCases.data),
                    current_page: e.data.hotCases.current_page,
                    last_page: e.data.hotCases.last_page
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a), wx.hideLoading({
                    success: function(a) {}
                });
            }
        });
    }
});